import React from 'react'


export default class Ipt extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            tagVal:""
        }
    }
    //监听值
    handleIptValue=(res)=>{
        this.setState({
            tagVal:res.target.value
        })
    }
    //键盘事件
    handleKeyDown = (res)=>{
        if( res.keyCode === 13 ){
            this.props.handleKeyDown(this.state.tagVal)
            this.setState({
                ...this.state,
                tagVal:""
            })
        }
    }
    render() {
        return (
            <div className={'ipt-box'}>
                <input onKeyDown={this.handleKeyDown} value={this.state.tagVal} onChange={this.handleIptValue} className={'ipt'} type="text"/>
            </div>
        );
    }

}
